"""This file is for basic OpenCV tutorial."""
import cv2
# import numpy as np
# from matplotlib import pyplot as plt

# ============= Example 1: Read and Show Image

# Example image from MIT Tangible Media Group's Programmable Droplets
# URL: https://tangible.media.mit.edu/project/programmable-droplets/
# img = cv2.imread('example.jpg', cv2.IMREAD_GRAYSCALE)

# Show image with title of Programmable Droplets Gray Scale
# cv2.imshow('Programmable Droplets Gray Scale', img)
# cv2.waitKey(0)

# ============= Example 2: Channels and Image Reading

# For better performance in the latter example,
# I changed the example image by an unofficial Windows Logo from Wikimedia:
# https://commons.wikimedia.org/wiki/File:Unofficial_Windows_logo_variant_-_2002–2012_%28Multicolored%29.svg

# Read the image in full color, which is default.
# Other possible read attributes can be seen at
# https://docs.opencv.org/3.4.19/d8/d6a/group__imgcodecs__flags.html#gga61d9b0126a3e57d9277ac48327799c80af660544735200cbe942eea09232eb822
# img = cv2.imread('windows.png', cv2.IMREAD_COLOR)

# # ignore the channels
# rows, cols, channels = img.shape

# cv2.imshow('Full Color', img)
# cv2.waitKey(0)

# cv2.imshow('1/4 of image', img[0:(rows // 4), 0:(cols // 4)])
# cv2.waitKey(0)

# for i in range(channels):
#     cv2.imshow('In Channel %d' % i, img[0:rows, 0:cols, i])
#     cv2.waitKey(0)

# =============== Example 2.5: Image Cutting

# img = cv2.imread('example.jpg')
# rows, cols, channels = img.shape

# white = 200

# cv2.imshow('Cut Image', img[white:(rows - white), white:(cols - white)])
# cv2.waitKey(0)

# =============== Example 3: Image Preprocessing
# ============= Example 3.1: Preprocessing: Shreholds
img = cv2.imread('example.jpg')
grayscaled = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# Method 1:
# retval, threshold = cv2.threshold(img, 100, 255, cv2.THRESH_BINARY)

# Method 2: with a Gray Scaled Image
retval, threshold = cv2.threshold(grayscaled, 150, 255, cv2.THRESH_BINARY)

# Method 3: With Adaptive Threshold
# threshold = cv2.adaptiveThreshold(grayscaled, 200,
#                                   cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
#                                   cv2.THRESH_BINARY, 115, 1)

# cv2.imshow('Original', img)
cv2.imshow('Threshold', threshold)
cv2.waitKey(0)

cv2.destroyAllWindows()
